/**
 * 
 */
package org.jenkon.assertion;

import java.sql.Connection;
import java.sql.SQLException;

/**
 * Class with assertion methods for SQL.
 * 
 * @author jkonopka
 * 
 */
public final class SQLConnectionAssert {

	/**
	 * hide public constructor for this util class.
	 */
	private SQLConnectionAssert() {
	}

	/**
	 * If the {@link Connection} is not open, then throwing {@link IllegalArgumentException}.
	 * 
	 * @param connection {@link Connection}
	 * @throws SQLException sql error handling
	 * @throws IllegalArgumentException
	 */
	public static void isOpen(final Connection connection) throws SQLException {
		isOpen(connection, "The connection is not open.");
	}

	/**
	 * If the {@link Connection} is not open, then throwing {@link IllegalArgumentException}.
	 * 
	 * @param connection {@link Connection}
	 * @param message the throwing message
	 * @throws SQLException sql error handling
	 * @throws IllegalArgumentException
	 */
	public static void isOpen(final Connection connection, final String message) throws SQLException {
		Assert.isTrue(!connection.isClosed(), message);
	}

	/**
	 * If the {@link Connection} is not closed, then throw {@link IllegalArgumentException}.
	 * 
	 * @param connection {@link Connection}
	 * @throws SQLException SQL error handling
	 * @throws IllegalArgumentException
	 */
	public static void isClosed(final Connection connection) throws SQLException {
		isClosed(connection, "The connection is not closed.");
	}

	/**
	 * If the {@link Connection} is not closed, then throw {@link IllegalArgumentException}.
	 * 
	 * @param connection {@link Connection}
	 * @param message the throwing message
	 * @throws SQLException SQL error handling
	 * @throws IllegalArgumentException
	 */
	public static void isClosed(final Connection connection, final String message) throws SQLException {
		Assert.isTrue(connection.isClosed(), message);
	}

}
